public class Solution387 {
    public int firstUniqChar(String s) {
        int[] start=new int[26];
        int[] times=new int[26];
        for (int i=0;i<s.length();i++) {
            char c=s.charAt(i);
            if (times[c-'a']==0){
                start[c-'a']=i;
            }
            times[c-'a']++;
        }
        int ans=Integer.MAX_VALUE;
        for (int i=0;i<26;i++){
            if (times[i]==1){
                ans=Math.min(ans,start[i]);
            }
        }
        return ans==Integer.MAX_VALUE?-1:ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution387().firstUniqChar("leetcode"));
    }
}
